package com.embrace.CookingForMyWife.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.embrace.CookingForMyWife.commom.R;
import com.embrace.CookingForMyWife.entity.Menu;
import com.embrace.CookingForMyWife.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;

    // 添加菜单项
    @PostMapping("/add")
    public R<Menu> addMenu(@RequestBody Menu menu) {
        menuService.save(menu);
        return R.success(menu);
    }

    // 获取当前用户所有菜单项
    @GetMapping("/list")
    public R<List<Menu>> list(@RequestParam Long userId) {
        QueryWrapper<Menu> query = new QueryWrapper<>();
        query.eq("user_id", userId);
        List<Menu> menus = menuService.list(query);
        return R.success(menus);
    }
}
